package site;

import java.util.ArrayList;
import java.util.Date;

import javax.ejb.Stateful;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

@Stateful
public class ArticleManager {
	
	private static int ident ;
	
	@PersistenceContext
	EntityManager em;
	
	public void ajouterArticle(String titre, int jj, int mm,
			int aaaa, String contenu) {
		
			@SuppressWarnings("deprecation")
			Date dateArticle = new Date (aaaa,mm,jj);
			Article article = new Article ();
			article.setTitre(titre);
			article.setContenu(contenu);
			article.setDateArticle(dateArticle);
			em.persist(article);
			ident = article.getIdent();

	}
	
	public void ajouterImage (String image) {
		
		Article article = em.find(Article.class, ident );
		article.setImageArticle(image);
	
	}
	
	@SuppressWarnings("unchecked")
	public ArrayList<Integer> listeIdentArticle() {
        return (ArrayList<Integer>) em.createQuery("SELECT r.ident FROM Article r").getResultList() ;
	}
	
	@SuppressWarnings("unchecked")
	public ArrayList<String> listeTitre() {
        return (ArrayList<String>) em.createQuery("SELECT r.Titre FROM Article r").getResultList() ;
	}
	
	@SuppressWarnings("unchecked")
	public ArrayList<Date> listeDate() {
        return (ArrayList<Date>) em.createQuery("SELECT r.dateArticle FROM Article r").getResultList() ;
	}
	
	@SuppressWarnings("unchecked")
	public ArrayList<String> listeContenu() {
        return (ArrayList<String>) em.createQuery("SELECT r.Contenu FROM Article r").getResultList() ;
	}
	
	
	@SuppressWarnings("unchecked")
	public ArrayList<String> listeImage() {
        return (ArrayList<String>) em.createQuery("SELECT r.imageArticle FROM Article r").getResultList() ;
	}
}
	
	
